//
//  StatisticsViewModel.swift
//  XingCeHelper
//
//  Created by 申铭 on 2022/12/9.
//

import UIKit

class StatisticsViewModel {

    func loadData()  -> [BaseSectionModel]  {
        var cellModels = [BaseCellModel]()
        var pieChartCellModels = [BaseCellModel]()
        
        let info1 = TimeStatisticsStore.queryTotalTime().et.formatHMS(sh: true, sm: true, ss: false)
        let info2 = KeyValueStore.get(Field.calc.doneTotalNumber.rawValue) ?? "0"
        let model1 = StatisticsCountCellModel(title1: "总计时", title2: "算数", info1: info1, info2: info2)
        let model2 = StatisticsCountCellModel(title1: "成语", title2: "规范词语", info1: "\(IdiomStore.getCount())", info2: "\(SpecificationStore.getCount())")
        model2.clickBtn = { str in
            if str == "成语" {
                UIViewController.currentNavController()?.pushViewController(IdiomListController(), animated: true) 
            } else if str == "规范词语" {
                UIViewController.currentNavController()?.pushViewController(SpecificationListController(), animated: true)
            }
        }
        
        cellModels.append(model1)
        cellModels.append(model2)
        pieChartCellModels.append(StatisticsPieChartCellModel())
        
        let segmentCellModel = YTDSegmentedCellModel(rowHeight: 60)
        
        var sections = [BaseSectionModel]()
        let section1 = BaseSectionModel(items: cellModels)
        let section2 = BaseSectionModel(items: [segmentCellModel])
        let section3 = BaseSectionModel(items: pieChartCellModels)
        sections.append(section1)
        sections.append(section2)
        sections.append(section3)
        
        return sections
    }
}
